package com.jdaw.datastructure.sort;

public class SelectionSort {
    public static void main(String[] args) {
        int[] arr={101,-10,119,1,-6,88,-9,55,14,11,2,-9};
        selectSort(arr);
    }

    public static void selectSort(int[] arr){
        for(int j=0;j< arr.length;j++) {
            int minIndex=j;
            int min=arr[minIndex];
            for (int i = minIndex; i < arr.length; i++) {
                if (arr[i] < min) {
                    min = arr[i];
                    minIndex = i;
                }
            }//这层循环是为了选出最小值
            int temp = arr[j];
            arr[j] = min;
            arr[minIndex] = temp;
        }
        for(int j=0;j<arr.length;j++){
            System.out.println(arr[j]);
        }
    }

}
